<template>
  <svg class="icon">
    <use :xlink:href="`#${iconName}`"/>
  </svg>
</template>

<script lang="ts">
//导入多个svg
// eslint-disable-next-line no-undef
let importAll = (requireContext: __WebpackModuleApi.RequireContext) => requireContext.keys().forEach(requireContext);
try {
  importAll(require.context('../assets/icons', true, /\.svg$/));//../assets/icons是文件路径
} catch (error) {
  console.log(error);
}

export default {
  name: 'Icon',
  props: ['iconName']
};
</script>

<style scoped>
.icon {
  width: 2em;
  height: 2em;
  margin: 5px 0;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>